<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>获取整数的上午下午后缀</title>
</head>

<body>
    <p>请在控制台查看结果</p>
    <script>
        const getMeridiemSuffixOfInteger = (num, lang = "en") => {
            const suffix = {
                "en": ["am", "pm"],
                "zh": ["上午", "下午"]
            }
            const [ams, pms] = suffix[lang];
            return num === 0 || num === 24 ? 12 + ams : num === 12 ? 12 + pms : num < 12 ? (num % 12) + ams : (num %
                12) + pms;
        }
        console.log(getMeridiemSuffixOfInteger(0));// '12am'
        console.log(getMeridiemSuffixOfInteger(11));// '11am'
        console.log(getMeridiemSuffixOfInteger(13));// '1pm'
        console.log(getMeridiemSuffixOfInteger(25));// '1pm'
        console.log(getMeridiemSuffixOfInteger(new Date().getHours(),'zh'));
    </script>
</body>

</html>